// const baseURL = "https://test.pinqiart.com/api/";
const baseURL = "https://www.pinqiart.com/api/";

export function request(option) {
	let sessionId = uni.getStorageSync("sessionId") || "";
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + option.url,
			method: option.method || "get",
			data: option.data || {},
			header: option.method = 'post' ? {
				'X-Requested-With': 'XMLHttpRequest',
				'Content-Type': option['Content-Type'] || 'application/x-www-form-urlencoded',
				'sessionId': sessionId,
			} : {
				'Content-Type': 'application/json',
				'X-Requested-With': 'XMLHttpRequest',
				'sessionId': sessionId,
			},
			success: (res) => {
				if (res.data.result == 2) {
					uni.clearStorageSync();
					uni.navigateTo({
						url: "/pages/index/getUserInfo"
					})
					
				}else if(res.data.result == 1){
					uni.showToast({
						"title": res.data.message,
						"icon": "none"
					})
					uni.clearStorageSync();
					uni.navigateTo({
						url: "/pages/index/choose"
					})
				} else {
					resolve(res.data);
				}
			},
			complete: (re) => {},
			fail: (err) => {
				reject(err)
			}
		})
	})
}
